<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>提交订单</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="stylesheet" href="{$smarty.const.PUBLIC_PATH}css/amazeui.min.css"/>
<link rel="stylesheet" href="{$smarty.const.IMAGES_PATH}style.css"/>
<script src="{$smarty.const.PUBLIC_PATH}js/jquery.min.js"></script>
<script src="{$smarty.const.PUBLIC_PATH}js/amazeui.min.js"></script>
<style type="text/css">
	.cart-panel-ul > li{
		height: 200px;
	}
	.up-radio-item{
		width: 95%;
		line-height: 60px;
		height: 60px;
	}
	.up-radio-item p{
		line-height: 30px;
		height: 30px;
		margin-top: 0px;
		margin-bottom: 0px;
	}
	.up-radio-item span {
		height:4rem;
	    background: #497bae;
	    color: #fff;
	    line-height: 4rem;
	    margin: 7px 10px 0px 0px;
	    border-radius: 5px;
	    padding: 0px 10px;
	    position: absolute;
	    float: right;
	    right: 0;
	    top: 26px;
}

</style>
</head>

<body>
<div class="container">
	<!--引入头文件-->
	{include file="../header.html"}
	<script>$('.title-link').text("提交订单")</script>

	<div class="gray-panel">
    	<div class="paoduct-title-panel">
        	<h2 class="checkout-h2"><span class="am-badge am-round am-badge-warning ">1</span> 确认订单信息</h2>
			<div class="cart-list-panel">
                <ul class="am-avg-sm-1 cart-panel-ul">
                   {foreach $goods as $k=>$v}
                   <li>
                        <div class="imgpanel"><a href="#"><img src="{$v.main_img}" class="am-img-responsive" /></a></div>
                        <div class="infopanel">
                            <h3><a href="#">{$v.name}</a></h3>
                            <p style="display: none;">{$v.id}</p>
                            <p style="display: none;">{$v.quantity}</p>
                            <p>价格：<span class="red2 bold">{$v.price}</span> 积分  X {$v.quantity}</p>
                        </div>
                    </li>
                    {/foreach}
                </ul>
            </div>
            <div class="cart_foot">共<span class="red2 bold" id="total_good">{count($goods)}</span>件商品；总价：<span class="red2 bold" id="total_amount">{$totalprice}</span>积分</div>
            <div class="cart-tool">
                <a class="am-btn am-btn-sm am-btn-success am-radius" href="shoppingcart.html">
                  <i class="am-icon-chevron-left"></i>
                  返回购物车
                </a>
            </div>
        </div>
        <div class="paoduct-title-panel">
        	<h2 class="checkout-h2"><span class="am-badge am-round am-badge-warning ">2</span> 确认收货地址</h2>
            <p><i class="am-icon-location-arrow"></i> 收货地址</p>
            <div class="withdrawals-panel" style="height: calc({count($address)+1} * 100px);">
        	{foreach $address as $k=>$v}
        	<div class="am-radio up-radio-item" style="position: relative;font-size: 17px;">
              <label>
                <input type="radio" name="addressuid" value="{$v.uid}" {if $v.first==1}checked{/if} style="width: 20px; height: 20px;position: relative; top: 10px;">
                	<p style="position: relative; top: 16px;left: 4px;"><i class="am-icon-user"></i>{$v.name}<i class="am-icon-phone" style="margin-left: 30px;"></i>{$v.phone}</p>
                	<p style="position: relative;left: 4px;margin-top: 19px;width: 65%;text-overflow:ellipsis;  white-space:nowrap;overflow:hidden;">{$v.province}{$v.city}{$v.town}{$v.detail}</p>
                	{if $v.first==1}
                	<a><span class="am-fr" style="right: 4rem;">默认</span></a>
                	{/if}
              </label>
            </div>
            {/foreach}
            <div style="text-align: center;margin-top: 35px;position: relative;width: 100%;">
            	<a href="{$smarty.const.__MODULE__}/User/addaddress/userid/{$smarty.session.id}" class="am-btn am-btn-danger am-btn-block am-radius" style="width:60%;position: absolute; left: 20%;">添加新地址</a>
            </div>
        </div>
        </div>
        <div class="paoduct-title-panel">
        	<h2 class="checkout-h2"><span class="am-badge am-round am-badge-warning ">3</span> 支付方式</h2>
            <ul class="am-list am-text-sm my-pay-ul">
            	<!--<li><a href="javascript:;" rel="1" class="hover"><span class="am-fr"><i class="am-icon-check-circle"></i>&nbsp;&nbsp;</span>&nbsp;&nbsp;&nbsp;&nbsp;<img src="{$smarty.const.IMAGES_PATH}wechat.png" class="payimg" />&nbsp;&nbsp;&nbsp;&nbsp;微信支付</a></li>
                <li><a href="javascript:;" rel="2"><span class="am-fr"><i class="am-icon-circle-thin"></i>&nbsp;&nbsp;</span><img src="{$smarty.const.IMAGES_PATH}alipay.png" class="payimg" /> 支付宝支付</a></li>-->
                <li><a><span class="am-fr">&nbsp;&nbsp;</span>&nbsp;&nbsp;&nbsp;&nbsp;<img src="{$smarty.const.IMAGES_PATH}money.png" class="payimg" />&nbsp;&nbsp;&nbsp;&nbsp;积分支付 &nbsp;&nbsp; <samll class="my-pay-yue">积分余额：<span class="red2">{$score}</span>  &nbsp;&nbsp;</samll></a></li>
            </ul>
            
            <div>
            	<ul class="am-avg-sm-2 am-text-center">
                	<li class="am-text-center am-padding-sm"><button type="button" class="am-btn am-btn-danger am-btn-block am-radius payorder">提交订单</button></li>
                    <li class="am-text-center am-padding-sm"><button type="button" class="am-btn am-btn-success am-btn-block am-radius">继续购物</button></li>
                </ul>
            </div>
        </div>
    </div>
    
    <footer data-am-widget="footer" class="am-footer am-footer-default" data-am-footer="{  }">
        <hr data-am-widget="divider" style="" class="am-divider am-divider-default"/>
      <div class="am-footer-miscs ">
        <p>CopyRight©2014 AllMobilize Inc.</p>
        <p>京ICP备13033158</p>
      </div>
    </footer>
    <!--底部-->
    {include file="../footer.html"}
</div>
<script type="text/javascript">
	$('.up-radio-item').height($('.up-radio-item').width()*0.17);
	
		$('.payorder').click(function(){
			
		if(!$("input[name='addressuid']:checked").val()){
			alert("尚未选择地址");
			return
		}
		
		var i=0;
		var goods=new Array();
		$('.cart-panel-ul').find('li').each(function() { //获取所有商品id和数量信息
//              console.log($(this));
                var id=$(this).children(".infopanel").children("p:eq(0)").text();
                var quantity=$(this).children(".infopanel").children("p:eq(1)").text();
            	goods[i]={
            		id:id,
            		quantity:quantity,
            	}
            	i++;
//				console.log(id)
//				console.log(quantity)
		})
		var data={ 
			goods:goods,
			addressuid:$("input[name='addressuid']:checked").val(),
			
		}
		$.post("{$smarty.const.__MODULE__}/Order/payorder", data,function(ret){
			console.log(ret);
			if(ret.errorcode){ //失败
				alert(ret.error);
			}else{ //下单成功
				window.location.href="{$smarty.const.__CONTROLLER__}/orders"
			}
		})
//		console.log(data);
	})
</script>
</body>
</html>
